package codepulse.blogmoon.cn.common.exception;




import codepulse.blogmoon.cn.common.enums.ErrorCode;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;


@Slf4j
@Getter
public class BizException extends RuntimeException {

    private Integer code;

    private String msg;

    /**
     * 是否上报异常及报警
     */
    private Boolean report = Boolean.FALSE;


    /**
     * 附加的业务数据
     */
    private Object data;


    public BizException() {
    }

    public BizException(String message){
        this(ErrorCode.SYSTEM_ERROR.getCode(), message, Boolean.FALSE, null);
    }

    public BizException(Integer code, String message) {
        this(code, message, Boolean.FALSE, null);
    }

    public BizException(ErrorCode errorCode) {
        this(errorCode.getCode(), errorCode.getMsg());
    }

    public BizException(Integer code, String message, Boolean report) {
        this(code, message, report, null);
    }

    public BizException(Integer code, String message, Object data) {
        this(code, message, Boolean.FALSE, data);
    }

    public BizException(Integer code, String message, Boolean report, Object data) {
        super(message);
        this.code = code;
        this.msg = message;
        this.report = report;
        this.data = data;
    }

    public BizException(Integer code, String message, Throwable cause) {
        this(code, message, cause, Boolean.FALSE);
    }

    public BizException(Integer code, String message, Throwable cause, Boolean report) {
        this(code, message, cause, report, null);
    }

    public BizException(Integer code, String message, Throwable cause, Boolean report, Object data) {
        super(message, cause);
        this.code = code;
        this.report = report;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public Boolean getReport() {
        return report;
    }

    public Object getData() {
        return data;
    }

    public String getMsg() {
        return msg;
    }

}
